<?php
namespace app\admin\controller\system;


use app\common\controller\Admin;
use app\common\traits\ControllerCurd;
use app\common\annotation\NodeAnnotation;
use think\facade\Request;


/**
 * @NodeAnnotation(
 *     title="系统发行",
 *     parent="admin/system.setting",
 *     is_menu=0,
 *     is_view=0
 * )
 */
class Version extends Admin
{
    use ControllerCurd;
    public $model ;

    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\admin\model\system\Version();
    }

    /**
     * @NodeAnnotation(
     *     title="版本发行",
     *     parent="admin/system.version",
     *     MenuRoot="admin/system.setting",
     *     is_menu = 1
     * )
     */
    public function index(\think\Request $request)
    {
        $keywords  = $request->param("keywords");

        $where = [];

        if($keywords) array_push($where,['author|version_number',"like","%$keywords%"]);

        $this->assign([
            "versionList" => $this->model->where($where)->order("update_time desc")->paginate(),
            "search"    => [
                "keywords" => $keywords
            ]
        ]);
        return $this->fetch();
    }

    /**
     * @NodeAnnotation(
     *     title="添加版本信息",
     *     parent="admin/system.version",
     *     MenuRoot="admin/system.setting",
     *     is_menu=0
     * )
     */
    public function addversion(Request $request)
    {
        $this->add(url("admin/system.version/index"));
        return $this->fetch();
    }

    /**
     * @NodeAnnotation(
     *     title="修改管理员",
     *     parent="admin/system.version",
     *     MenuRoot="admin/system.setting",
     *     is_menu=0,
     *     auth=0
     * )
     */
    public function editversion(Request $request,$id=0)
    {
        $this->edit(url("admin/system.version/index"));

        $this->assign([
            "versions" => $this->model->findData($id)
        ]);

        return $this->fetch();
    }

    /**
     * @NodeAnnotation(
     *     title="删除版本",
     *     parent="admin/system.version",
     *     MenuRoot="admin/system.setting",
     *     is_menu=0,
     *     is_view=0
     * )
     */
    public function delversion(Request $request)
    {
        $this->del();
    }

}